package shuati.chuanzhibei;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * @Date : 2022/11/26
 * @Description:
 */
public class PC {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        System.out.println(js(list,m));
    }
    public static int js(List list,int m){
        if(m>=list.size()-1) return 0;
        else{

        for (int i = 0; i <m; i++) {
            Integer max = (Integer) Collections.max(list);
            Integer min= (Integer) Collections.min(list);
            int sum=0;
            for (int j = 0; j < list.size(); j++) {
                sum = (int)list.get(j) + sum;
            }

            if( (int)Collections.max(list)-(int)Collections.min(list)  >sum/list.size()){
                list.set(list.indexOf(min), max);
            } else
                list.set(list.indexOf(max), min);
        }
        return (int)Collections.max(list)-(int)Collections.min(list);
    }
}}
